import LXCOM from '../common/common.js'
import ActPkg from '../graph/action/rectaction.js'
import GlobalConst from '../common/globalConst.js'
import UtilFuncs from '../common/tools/utilfuncs.js'
var funcs = UtilFuncs.UtilFuncs;
import Coord from '../common/struct/coord.js'
import rectgraph from './rectgraph.js'
import {LGXEnums}  from '../common/sysenum.js'


import globalConst from '../common/globalConst.js'
var global = globalConst.GlobalConst;

class MultiSelRectGraph extends rectgraph.RectGraph {
    constructor(type) {
        super(type);
        var p = new Coord.MultiPos();
        this.setPos(p);

        var action = new ActPkg.RectGraphAction(this);
        this.setActionSvc(action);
        this.m_graphType = LGXEnums.LGXGraphType.MultiSel_Rect_Type;
        this.m_rotHandLenth = 0.1;
        this.m_endSelRect = false;
        this.m_rotCnt = new LXCOM.LGXPoint();
        this.m_modifyCharacter = 0;
        this._lineDef.linemode = LGXEnums.LGXLineMode.Dash_Dash;
    }

    display(map, mapInfo,forClip) {
        this._fillDef.fillStyle = LGXEnums.LGXFillStyle.EMPTY;
        super.display(map, mapInfo);
        if (this._useful == 1 && this._finishFlag == 1) {
            super.displayFeaturePoint(map, mapInfo);
        }
    }

    calScope(mapscale) {
        super.calScope(mapscale);
    }

    distance(tPos, scaling, mapscale) {
        var position = this.getPos();
        var lenth = position.posList.length;
        if (lenth < 2) {
            return -1;
        }
        if (!super.preCheckInScope(tPos, scaling)) {
            return -1;
        }

        var cmpGap = super.getSelCmpGap(scaling, mapscale);
        var dis = -1;
        var pCntPos = null;
        var pPrePos = position.posList[0];
        for (var i = 0; i < lenth - 1; i++) {
            pCntPos = position.posList[i + 1];
            var lLen = funcs.distanceLineSec4Visual(tPos, pPrePos, pCntPos, scaling);
            if ((lLen < dis) || (dis < 0)) {
                dis = lLen;
            }
            if (dis <= cmpGap) {
                return 0;
            }
            pPrePos = pCntPos;
        }
        return 0;//dis;
    }


    calculateSubKind(tPoint, scaling, mapscale) {
        let seleKind = 0;
        return seleKind;
    }

    chkSelRotHandPot(tPoint, scaling) {
        let flag = false;
        var ptlst = this.getScopeVertexPtLst(scaling);
        if (ptlst.length == LGXEnums.LGXModGraphKind.Drag_MAXCount) {
            let rotHandPot = ptlst[LGXEnums.LGXModGraphKind.Drag_rotHand - 1];
            console.log("mouspt,x="+tPoint.x + " y="+tPoint.y + "rotHandPot,x="+rotHandPot.x + ",y="+rotHandPot.y);
            const cmpGap = global.SelectGap;
            let dis = funcs.distancePoint(tPoint, rotHandPot, scaling);
            if (dis <= cmpGap && dis >= 0) {
                flag = true;
            }
        }
        ptlst.length = 0;
        return flag;
    }

    movePosOffset(tOffset, modCmdInfo) {
        if (this._selKind < 1) {
            return;
        }

        var position = this.getPos();
        var lenth = position.posList.length;
        if (this._selKind > lenth) {
            for (var i = 0; i < lenth; i++) {
                var pPos = position.posList[i];
                pPos.x += tOffset.x;
                pPos.y += tOffset.y;
            }
        }
        else if (this._selKind <= lenth && this._selKind > 0) {
            pPos = position.posList[this._selKind - 1];
            pPos.x += tOffset.x;
            pPos.y += tOffset.y;
        }
    }
    getMainFeaturePTLst(tFeaturePTLst) {
        var position = this.getPos();
        var lenth = position.posList.length;
        for (var i = 0; i < lenth; i++) {
            var pt = position.posList[i];
            tFeaturePTLst.push({pt,kind:LGXEnums.AuxPointKind.end});
        }
    }

    setModifyCharacter(kind) { this.m_modifyCharacter = kind; }
    getModifyCharacter() { return this.m_modifyCharacter; }

}

export default { MultiSelRectGraph }



